package main

import "fmt"

/**
 * @author: guangcheng
 * @date:   2020/11/18 12:40
 * @version  V1.0
 * @description:
 *
 */
func main() {

	//way1
	var a map[string]string
	a = make(map[string]string, 10)
	a["no1"] = "mandy"
	a["no2"] = "sandy"
	fmt.Println(a)

	a["no1"] = "hello"
	fmt.Println(a)

	a["no3"] = "mandy"
	fmt.Println(a)

	//way2
	var cities = make(map[string]string)
	cities["no1"] = "beijing"
	cities["no2"] = "shanghai"
	fmt.Println("cities=", cities)

	//way3
	var city map[string]string = map[string]string{
		"no1": "beijing",
		"no2": "shanghai", //哪怕是最后一个,也需要逗号
	}
	fmt.Println("city=", city)

	//练习
	studentMap := make(map[string]map[string]string)
	//注意: 多重map, 每一重map都需要make空间
	studentMap["stu001"] = make(map[string]string) //注意容易忽略这个
	//赋值
	studentMap["stu001"]["name"] = "tom"
	studentMap["stu001"]["sex"] = "man"
	studentMap["stu001"]["address"] = "shanghai"

	studentMap["stu002"] = make(map[string]string) //注意容易忽略这个
	studentMap["stu002"]["name"] = "cat"
	studentMap["stu002"]["sex"] = "nv"
	studentMap["stu002"]["address"] = "beijing"

	fmt.Println(studentMap)

	/**
	stuNum= stu001
	 address=shanghai
	 name=tom
	 sex=man

	stuNum= stu002
	 sex=nv
	 address=beijing
	 name=cat
	*/
	for k0, v0 := range studentMap {
		fmt.Println("stuNum=", k0)
		for k, v := range v0 {
			fmt.Printf(" %v=%v\n", k, v)
		}
		fmt.Println()
	}

	fmt.Println(len(studentMap))           //2: sut001 stu002
	fmt.Println(len(studentMap["stu001"])) //3: name sex address

}
